Add SemanticCache vector index config#619
Conversation
Signed-off-by: Omri SirComp <omribz156@gmail.com>
There was a problem hiding this comment.
Pull request overview
Adds a configurable vector-index configuration path for SemanticCache, allowing the cache’s vector field to be created with HNSW (or other supported RedisVL vector algorithms) instead of being hardcoded to FLAT, and documents the new configuration in the LLM cache user guide.
Changes:
- Extend
SemanticCacheIndexSchema.from_paramsto acceptvector_index_configand merge it into the vector field attrs while protecting vectorizer-derived attrs (dims,datatype,distance_metric). - Add
vector_index_configplumbing toSemanticCacheconstructor so the schema/index can be created with a non-FLAT algorithm (e.g., HNSW). - Add unit tests for default FLAT behavior, HNSW config acceptance, and invalid config rejection; update the LLM cache notebook with a configuration example.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
redisvl/extensions/cache/llm/schema.py |
Adds vector_index_config support to the semantic cache index schema builder while preventing overrides of derived attrs. |
redisvl/extensions/cache/llm/semantic.py |
Wires vector_index_config through SemanticCache initialization into schema/index creation. |
tests/unit/test_llmcache_schema.py |
Adds unit coverage for FLAT default, HNSW config, and invalid algorithm/override behavior. |
docs/user_guide/03_llmcache.ipynb |
Documents how to configure the semantic cache’s vector index algorithm (example: HNSW). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| filterable_fields: list[dict[str, Any]] | None = None, | ||
| vector_index_config: dict[str, Any] | None = None, | ||
| redis_client: Redis | None = None, | ||
| redis_url: str = "redis://localhost:6379", | ||
| connection_kwargs: dict[str, Any] = {}, |
There was a problem hiding this comment.
Thanks, fixed in 40297d2. I moved vector_index_config after overwrite in SemanticCache.init and kept the docstring in the same order, so existing positional redis_client/redis_url calls stay compatible. Verified with pytest --noconftest tests/unit/test_llmcache_schema.py, black --check, compileall, and git diff --check.
Summary
Addresses #602.
vector_index_configtoSemanticCacheso the cache vector field can be created with HNSW or other supported vector index options instead of always using FLAT.dims,datatype, anddistance_metricderived from the vectorizer / semantic-cache COSINE behavior.Verification
.venv\Scripts\python.exe -m pytest --noconftest tests/unit/test_llmcache_schema.py.venv\Scripts\python.exe -m black --check redisvl/extensions/cache/llm/schema.py redisvl/extensions/cache/llm/semantic.py tests/unit/test_llmcache_schema.py.venv\Scripts\python.exe -m compileall redisvl/extensions/cache/llm/schema.py redisvl/extensions/cache/llm/semantic.py tests/unit/test_llmcache_schema.py.venv\Scripts\python.exe -c "import json; json.load(open('docs/user_guide/03_llmcache.ipynb', encoding='utf-8')); print('notebook json ok')"git diff --checkI also tried the normal pytest command first, but local execution without
--noconftestis blocked on this Windows machine because the repo autouse fixture invokes Docker Compose and the Docker CLI is not available here.This was implemented with Codex assistance, with the patch kept focused on the cache schema/config path and docs.
Note
Low Risk
Additive constructor option with unchanged default FLAT behavior; risk is mainly misconfigured index settings affecting search performance, not data or auth paths.
Overview
Adds optional
vector_index_configonSemanticCacheso the Redis vector field for prompt embeddings can use HNSW (or other supported algorithms) instead of always FLAT, while dims, datatype, and cosine distance still come from the vectorizer and are rejected if overridden in config.SemanticCacheIndexSchema.from_paramsmerges user config onto the default FLAT attrs and passes the result into index creation; the LLM cache user guide documents HNSW setup and notes that the algorithm is fixed after index creation (recreate withoverwrite=Trueto change it).Unit tests cover default FLAT, HNSW options, invalid algorithms, and blocked overrides of vectorizer-derived fields.
Reviewed by Cursor Bugbot for commit 40297d2. Bugbot is set up for automated code reviews on this repo. Configure here.